<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.1.1.min.js"></script>
    <style type="text/css">
        .new{
            float: left;
            width: 50%;
        }
        .old{
            margin-left: 50%;
        }
        input{
            display: none;
        }
    </style>
    <script>
        /**
         * 文件上传
         * @param url: 请求的url
         * @param data: request参数
         * @param type：get/put/post/delete
         * @param datatype：json(默认)
         * @param successfn: 请求成功的回调函数
         * @param errorfn：请求异常回调函数
         */
        function fnUploadFile (url, data, type, datatype, successfn, errorfn) {
            type = (type==null || type=="" || typeof(type)=="undefined")? "post" : type;
            data = (data==null || data=="" || typeof(data)=="undefined")? "" : data;
            $.ajax({
                type: type,
                async: true,
                data: data,
                url: url,
                processData : false,
                contentType : false,
                dataType: datatype,
                success: function(response) {
                    console.log(response);
                },
                error: function(event,jqXHR,ajaxSettings,thrownError) {
                    alert("1="+event.status);
                    alert("2="+jqXHR);
                    alert("3="+ajaxSettings);
                    alert("4="+thrownError);
                    errorfn(response);
                },
                complete: function (response) {
                    //console.log("-----complete-----", response);
                }
            });
        }

        function upload() {
            var data = JSON.stringify({file: "/guoge.mp3"});
            fnUploadFile('http://api-hiworld.haibian.com/teacher/class/mp3/upload','','post','',function(resp) {
                console.log("success");
                console.log(resp);
            },function (res) {
                console.log("error");
                console.log(res);
            })
        }

    </script>
</head>
<body>
    <div class="new">
        <button onclick="upload()">upload_new</button>
        <span id="time_new"></span>
    </div>
    <div class="old">
        <button>upload_old</button>
        <span id="time_old"></span>
    </div>
</body>
</html>